import Vue from 'vue'
import VueRouter from 'vue-router'
Vue.use(VueRouter);

export const routes = [
  {
    path: '/',
    name: 'Login',
    component: () => import("@/views/login.vue"),
  },
  {
    path: '/mainPage',
    name: 'mainPage',
    component: resolve => require(['@/views/mainPage.vue'], resolve),
    // alias:'/commodityIndex',
    redirect: {
      name: 'commodityIndex'
    },
    // meta: {
    //   requiresAuth: true  // 访问该路由时需要判断是否登录
    // }
    children: [
      {
        path: '/commodityIndex',
        component: () => import("@/views/commodity/commodity_index.vue"),
        name: 'commodityIndex',
        meta:{
          id:'1',
          name:['首页','传值'],
          path:['/commodityIndex','/commodityIndex'],
          title:'传值'
        },
        children: [
          {
            path: '/commodityState',
            component: () => import("@/views/commodity/commodity_state.vue"),
            name: 'commodityState',
          },
          {
            path: '/commodityStock',
            component: () => import("@/views/commodity/commodity_stock.vue"),
            // components: {
            //   default:()=> import ("@views/commodity/commodity_stock.vue"),
            //   a:() => import("@/views/commodity/commodity_state.vue")
            // },
            name: 'commodityStock',
          },
        ]
      },
      {
        path: '/direct',
        name: 'direct',
        component: () => import("@/views/direct/direct.vue"),
        meta:{
          id:'2',
          title:'自定义组件'

        }
      },
      {
        path: '/modifier',
        name: 'modifier',
        component: () => import("@/views/modifier/modifier.vue"),
        meta:{
          id:'3',
        title:'修饰符'
        }
      },
      {
        path: '/getmap',
        name: 'getmap',
        component: () => import("@/views/map/map.vue"),
        meta:{
          
          id:'4',
        title:'调用高德地图'
        }
      },
    ]
  },
];


// 动态路由
export const asyncRoutes = [
{
    path: '/echart',
    name:'echart',
    component: ()=>import("@/views/echart/echart.vue"),
    meta:{
      id:'5',
      title:'调用图表'
      }
  },
  {
    path: '/slot',
    name:'slot',
    component: ()=>import("@/views/slot/slot.vue"),
    meta:{
      id:'6',
      title:'插槽'
      }
  }
];

let newRouter=routes;
newRouter[1].children=routes[1].children.concat(asyncRoutes)



const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

export default router
